package com.yayun.merchant.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yayun.common.annotation.Log;
import com.yayun.common.core.controller.BaseController;
import com.yayun.common.core.domain.AjaxResult;
import com.yayun.common.enums.BusinessType;
import com.yayun.merchant.domain.UmsMemberAddress;
import com.yayun.merchant.service.IUmsMemberAddressService;
import com.yayun.common.utils.poi.ExcelUtil;
import com.yayun.common.core.page.TableDataInfo;

/**
 * 会员收货地址Controller
 * 
 * @author yayun
 */
@RestController
@RequestMapping("/member/address")
public class UmsMemberAddressController extends BaseController {
    @Autowired
    private IUmsMemberAddressService umsMemberAddressService;

    /**
     * 查询会员收货地址列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UmsMemberAddress umsMemberAddress) {
        startPage();
        List<UmsMemberAddress> list = umsMemberAddressService.selectUmsMemberAddressList(umsMemberAddress);
        return getDataTable(list);
    }

    /**
     * 获取会员收货地址详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(umsMemberAddressService.selectUmsMemberAddressById(id));
    }

    /**
     * 新增会员收货地址
     */
    @PostMapping
    public AjaxResult add(@RequestBody UmsMemberAddress umsMemberAddress) {
        return toAjax(umsMemberAddressService.insertUmsMemberAddress(umsMemberAddress));
    }

    /**
     * 修改会员收货地址
     */
    @PutMapping
    public AjaxResult edit(@RequestBody UmsMemberAddress umsMemberAddress) {
        return toAjax(umsMemberAddressService.updateUmsMemberAddress(umsMemberAddress));
    }

    /**
     * 删除会员收货地址
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(umsMemberAddressService.deleteUmsMemberAddressByIds(ids));
    }

    /**
     * 设置默认地址
     */
    @PutMapping("/default/{id}")
    public AjaxResult setDefault(@PathVariable("id") Long id) {
        return toAjax(umsMemberAddressService.setDefault(id));
    }
} 